<template>
  <div class="container">
    <div class="liveContainer">
      <div class="liveTitle">
        <h1>长视频</h1>
        <div class="liveText">
          <ElButton
            size="small"
            style="margin-right: 14px"
            round
            v-for="item in categoryList"
            :key="item.id"
            @click="waitchMv(item.id)"
            :class="categoryId == item.id ? 'active' : ''"
          >
            {{ item.name }}
          </ElButton>
          <span>更多</span>
          <ArrowRight style="width: 1em; height: 1em; margin-right: 8px" />
        </div>
      </div>
      <div class="liveContext">
        <!-- 直播 -->
        <div class="liveVideo"  v-if="status">
          <div class="liveImg">
            <img
              :src="groupMvList[0].data.coverUrl"
              alt=""
            />
            <div class="liveDesc">
              <h5>{{groupMvList[0].data.title}}</h5>
              <div class="liveInfo">
                <StarFilled
                  style="width: 1em; height: 1em; margin-right: 8px"
                />
                <span>{{groupMvList[0].data.praisedCount}}人喜欢</span>
              </div>
            </div>
          </div>
        </div>
        <!-- 直播列表 -->
        <div class="liveImgList">
          <div class="videoBox" v-for="item in groupMvList" :key="item.data.vid">
            <div class="videoImg">
              <img
                :src="item.data.coverUrl"
                alt=""
              />
            </div>
            <div class="videoContext">
              <h5>{{item.data.title}}</h5>
              <div class="videoInfo">
                <StarFilled
                  style="width: 1em; height: 1em; margin-right: 8px"
                />
                <span>{{item.data.praisedCount}}人喜欢</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from "vue";

export default defineComponent({
  name: "LongVideo",
});
</script>

<script lang="ts" setup>
import { StarFilled, ArrowRight } from "@element-plus/icons";
import { getCategoryListApi, getGroupMvApi } from "@/api/home";

// mv视频分类列表
const categoryList = ref([]);
// 储存点击的分类ID
const categoryId = ref(58100)
// 分类视频
const groupMvList = ref([])

// 防止页面渲染时，数据还没有回来页面报错的情况
const status =ref(false)

// 用户点击分类的回调函数
const waitchMv = (id:number) => {
  // console.log(id);
  categoryId.value = id
  // console.log('点击了',id);
  getGroupMv(id)
}

// 获取分类视频
const getGroupMv = async (id) =>{
  const res1 = await getGroupMvApi(id)
  // console.log(res1.datas);
  groupMvList.value = res1.datas.slice(1,7)
}

onMounted(async () => {
  const res = await getCategoryListApi();
  // console.log(res);
  categoryList.value = res.data;
  await getGroupMv(categoryId.value)
  status.value = true
});
</script>

<style lang="less" scoped>
// 内容盒子
.container {
  margin: 0 auto;
  width: 1126px;
  //   margin-bottom: 200px;
}
// 标题
.liveTitle {
  height: 42px;
  line-height: 42px;
  display: flex;
  margin-bottom: 24px;
  h1 {
    margin: 0;
    margin-right: 24px;
  }
  .liveText {
    display: flex;
    align-items: center;
  }
}
// 视频
.liveContext {
  display: flex;
  .liveVideo {
    width: 565px;
    // height: 450px;
    // border: 1px solid;
    margin-right: 16px;
  }
  .liveImg {
    width: 565px;
    flex-shrink: 0;
    img {
      width: 100%;
      border-radius: 5px;
    }
    .liveDesc {
      padding-top: 16px;
      h5 {
        margin: 0;
        width: 159.5px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 15px;
      }
      .liveInfo {
        display: flex;
        margin-top: 5px;
        color: #999;
      }
    }
  }
  .liveImgList {
    width: 562px;
    // border: 1px solid;
    display: flex;
    flex-wrap: wrap;
    overflow: hidden;
    flex-shrink: 0;
    .videoBox {
      width: 170px;
      margin-right: 16px;
      margin-bottom: 46px;
      .videoImg {
        width: 100%;
        height: 108px;
        font-size: 0;
        overflow: hidden;
        // position: relative;
        border-radius: 4px;
        img {
          width: 100%;
          // position: absolute;
          // top: -90px;
          height: 100%;
        }
      }
      .videoContext {
        padding-top: 16px;
        h5 {
          margin: 0;
          width: 159.5px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          font-size: 15px;
        }
        .videoInfo {
          display: flex;
          margin-top: 5px;
          color: #999;
        }
      }
    }
  }
}
.active{
  background-color: #fe3666;
  color: #fff;
}
</style>
